package com.example.hotHub.controller;

import com.example.hotHub.common.R;
import com.example.hotHub.enums.AstroEnum;
import com.example.hotHub.model.Astro;
import com.example.hotHub.service.AstroService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @author aaa
 */
@CrossOrigin
@Api(tags = "星座爬取控制器")
@RestController
public class AstroController {

    @Autowired
    private AstroService astroService;

    @GetMapping({"astro"})
    public R getAstroToday(@RequestParam(defaultValue = "today")String day, @RequestParam(defaultValue = "libra") String astroName) {
        Astro astro = null;
        switch (day) {
            case "today":
                astro = astroService.getAstroToday(astroName);
                break;
            case "tomorrow":
                astro = astroService.getAstroTomorrow(astroName);
                break;
            case "week":
                astro = astroService.getAstroWeek(astroName);
                break;
            case "month":
                astro = astroService.getAstroMonth(astroName);
                break;
            case "year":
                astro = astroService.getAstroYear(astroName);
                break;
            case "love":
                astro = astroService.getAstroLove(astroName);
                break;
        }
        return R.success(astro);
    }

    @GetMapping("/test")
    public R getAstroOptions() {
        List<Object> astroOptions = new ArrayList<>();
        for (AstroEnum astroEnum : AstroEnum.values()) {
            HashMap<String, String> data = new HashMap<>();
            data.put("label", astroEnum.getLabel());
            data.put("value", astroEnum.getName());
            String time = "" + astroEnum.getBeginMonth() + "月" + astroEnum.getBeginDay() + "日" + " - " + astroEnum.getEndMonth() + "月" + astroEnum.getEndDay() + "日";
            data.put("time", time);
            astroOptions.add(data);
        }
        return R.success(astroOptions);
    }

    @GetMapping({"astro/today/{astroName}"})
    public R getAstroToday(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroToday(astroName);
        return R.success(astro);
    }

    @GetMapping("astro/tomorrow/{astroName}")
    public R getAstroTomorrow(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroTomorrow(astroName);
        return R.success(astro);
    }

    @GetMapping("astro/week/{astroName}")
    public R getAstroWeek(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroWeek(astroName);
        return R.success(astro);
    }

    @GetMapping("astro/month/{astroName}")
    public R getAstroMonth(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroMonth(astroName);
        return R.success(astro);
    }

    @GetMapping("astro/year/{astroName}")
    public R getAstroYear(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroYear(astroName);
        return R.success(astro);
    }

    @GetMapping("astro/love/{astroName}")
    public R getAstroLove(@PathVariable("astroName") String astroName) {
        Astro astro = astroService.getAstroLove(astroName);
        return R.success(astro);
    }

}
